package com.example.shop.order.dao;

import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.shop.order.dto.OrderBrowseInfo;
import com.example.shop.order.dto.OrderQueryParam;
import com.example.shop.order.typehandler.OrderStateTypeHandler;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderBrowseInfoDao {


    @Results(id = "OrderBrowseInfoResultMap",value = {
            @Result(column = "goods_id",property = "goodsInfo",
                    one = @One(select = "com.example.shop.order.dao.OrderGoodsInfoDao.selectById")),
            @Result(column = "order_state",property = "orderState",typeHandler = OrderStateTypeHandler.class)
    })
    @Select("<script>" +
            "select order_id,user_id,goods_id,order_state,user_purchased_goods_class," +
            "user_purchased_number,user_buy_time,real_pay " +
            "from `order` " +
            "where user_id = ${userId} and " + OrderQueryParam.QUERY_SQL+
            "</script>")
    List<OrderBrowseInfo> select(@Param("userId") long userId,@Param(Constants.WRAPPER) OrderQueryParam queryParam);

    @ResultMap("OrderBrowseInfoResultMap")
    @Select("<script>" +
            "select o.order_id,o.user_id,o.goods_id,o.order_state,o.user_purchased_goods_class," +
            "o.user_purchased_number,o.user_buy_time,real_pay " +
            "from `order` o join goods g on o.goods_id = g.goods_id " +
            "where g.merchant_id = ${merchantId} and " + OrderQueryParam.QUERY_SQL+
            "</script>")
    List<OrderBrowseInfo> selectMerchantOrderList(@Param("merchantId")long merchantId,@Param(Constants.WRAPPER)OrderQueryParam queryParam);
}
